﻿#ifndef _DB_IFEATURECLASS_H
#define _DB_IFEATURECLASS_H

#include "udatabase/interface/idataset.h"
#include "udatabase/interface/ifield.h"
#include "udatabase/interface/ifields.h"
#include "udatabase/interface/iqueryfilter.h"
#include "geometry/interface/igeometry.h"
#include "udatabase/interface/itableproxy.h"
#include "udatabase/dll_cfg.h"

namespace FD
{
	namespace Utility
	{
		namespace DB
		{
			namespace Interface
			{
				class IFeature;
				class IFeatureIterator;
				class IFeatureSelection;

				/// <summary>
				/// 要素类 类型枚举
				/// </summary>
				enum FeatureClassType
				{
					/// <summary>
					/// 未知类型
					/// </summary>
					FCT_UNKNOWN                    = 0,
					/// <summary>
					/// 矢量要素类类型
					/// </summary>
					FCT_VECTORFEATURECLASS         = 1,
					/// <summary>
					/// 实体要素类类型
					/// </summary>
					FCT_ENTITYDATASET              = 2,

					FCT_MESHDATASET				    =3 ,
					/// <summary>
					/// 特效要素类类型
					/// </summary>
					FCT_EFFECTDATASET			   =4  ,
					/// <summary>
					/// 注记要素类类型
					/// </summary>
					FCT_ANNOTATION			        = 5,
					FCT_VECTORFILE_FEATURECLASS	=	6,
					FCT_VECTORFILE_ANNOTATION			=	7,
					FCT_VECTORFILE_CADFEATURECLASS  = 8
				};

				/// <summary>
				/// 要素类接口
				/// </summary>
				class FD_DB_Export IFeatureClass : public FD::Utility::DB::Interface::IDataset
				{
				public:	
					/// <summary>
					/// 默认析构函数
					/// </summary>
					virtual ~IFeatureClass();
				public:
					/// <summary>
					/// 获取要素数据集类型
					/// </summary>
					/// <returns>要素数据集类型</returns>
					virtual FD::Utility::DB::Interface::FeatureClassType getFeatureClassType() const;
					/// <summary>
					/// 获取几何体类型
					/// </summary>
					/// <returns>几何体类型枚举</returns>
					virtual FD::Kernel::Geometry::Interface::GeometryType getGeometryType() const;
					/// <summary>
					/// 获取要素数据集的字段集合
					/// </summary>
					/// <returns>字段集合对象，内部引用，无需释放</returns>
					virtual const FD::Utility::DB::Interface::IFields* getFieldsRef() const;
					/// <summary>
					/// 获取要素数据集的字段数目
					/// </summary>
					/// <returns>字段数目</returns>
					virtual UINT32 getFieldCount() const;
					/// <summary>
					/// 获取指定索引的字段对象
					/// </summary>
					/// <param name="index">指定索引</param>
					/// <returns>字段对象，内部引用，无需释放</returns>
					virtual const FD::Utility::DB::Interface::IField* getFieldRef(UINT32 index)const;
					/// <summary>
					/// 是否能找到指定字段名称。
					/// </summary>
					/// <param name="fieldName">指定字段名称</param>
					/// <returns>如果找到，返回索引；如果找不到，返回-1</returns>
					virtual INT32 findField(const String& fieldName) const;
					/// <summary>
					/// 获取几何体字段对象
					/// </summary>
					/// <returns>几何体字段对象，内部引用，无需释放</returns>
					virtual const FD::Utility::DB::Interface::IField* getGeometryField() const;
					/// <summary>
					/// 获取ID字段对象
					/// </summary>
					/// <returns>ID字段对象，内部引用，无需释放</returns>
					virtual const FD::Utility::DB::Interface::IField* getIDField() const;
					/// <summary>
					/// 获取空间索引类型枚举
					/// </summary>
					/// <returns>空间索引类型枚举</returns>
					virtual FD::Utility::DB::Interface::SpatialIndexEnum getSpatialIndexEnum() const;
					/// <summary>
					/// 获取指定ID的要素
					/// </summary>
					/// <param name="id">指定ID</param>
					/// <returns>要素对象。如果无该ID，返回NULL</returns>
					virtual  FD::Utility::DB::Interface::IFeature* getFeature(UINT32 id);
					/// <summary>
					/// 按照指定条件，进行查询
					/// </summary>
					/// <param name="filter">指定查询条件</param>
					/// <returns>要素查询结果迭代器</returns>
					virtual  FD::Utility::DB::Interface::IFeatureIterator* query(FD::Utility::DB::Interface::IQueryFilter* filter);
					/// <summary>
					/// 按照指定条件，进行选择
					/// </summary>
					/// <param name="filter">指定空间索引类型</param>
					/// <returns>要素选择器</returns>
					virtual  FD::Utility::DB::Interface::IFeatureSelection* select(FD::Utility::DB::Interface::IQueryFilter* filter);
					/// <summary>
					/// 获取指定查询条件的要素数目
					/// </summary>
					/// <param name="filter">查询条件</param>
					/// <returns>要素数目</returns>
					virtual UINT32 getFeatureCount(FD::Utility::DB::Interface::IQueryFilter* filter);
					/// <summary>
					/// 为数据集，创建指定空间索引
					/// </summary>
					/// <param name="spaIndex">指定空间索引类型</param>
					/// <returns>ture，成功；false，失败</returns>
					virtual bool createSpatialIndex(FD::Utility::DB::Interface::SpatialIndexEnum spaIndex);
					/// <summary>
					/// 重建空间索引
					/// </summary>
					/// <returns>true，成功；false，失败</returns>
					virtual bool rebulidSpatialIndex();
					/// <summary>
					/// 删除空间索引
					/// </summary>
					/// <returns>true，成功；false，失败</returns>
					virtual bool deleteSpatialIndex();
					/// <summary>
					/// 添加字段
					/// </summary>
					/// <param name="field">指定索引</param>
					/// <returns>ture，成功；false，失败</returns>
					virtual bool addField(const FD::Utility::DB::Interface::IField* field);
					/// <summary>
					/// 删除指定字段
					/// </summary>
					/// <param name="field">指定字段</param>
					/// <returns>ture，成功；false，失败</returns>
					virtual bool deleteField(const FD::Utility::DB::Interface::IField* field);
					/// <summary>
					/// 创建要素缓存对象，内存中创建，用于一次性写入数据集。
					/// </summary>
					/// <returns>要素对象</returns>
					virtual FD::Utility::DB::Interface::IFeature* createFeatureBuffer();
					/// <summary>
					/// 在数据集上，插入新要素。
					/// </summary>
					/// <param name="feature">返回的要素对象</param>
					/// <returns>ture，成功；false，失败</returns>
					virtual bool insert( FD::Utility::DB::Interface::IFeature* feature);
					/// <summary>
					/// 插入已知要素到数据集中
					/// </summary>
					/// <param name="buffer">指定要素对象</param>
					/// <returns>返回插入索引</returns>
					virtual UINT32 insertFeatureBuffer(const FD::Utility::DB::Interface::IFeature* buffer);
					/// <summary>
					/// 更新已知要素
					/// </summary>
					/// <param name="buffer">要素对象</param>
					/// <returns>ture，成功；false，失败</returns>
					virtual bool update(const FD::Utility::DB::Interface::IFeature* buffer);
					/// <summary>
					/// 获取数据集的范围
					/// </summary>
					/// <returns>包围盒对象</returns>
					virtual FD::Kernel::Geometry::Interface::IEnvelope* getEnvelopeRef() const;
					/// <summary>
					/// 获取数据集的空间坐标系参考对象
					/// </summary>
					/// <returns>空间坐标参考系对象，内部引用，无需释放</returns>
					virtual const FD::Kernel::Math::SpatialReference* getSpatialReferenceRef() const;
					/// <summary>
					/// 删除指定ID的要素
					/// </summary>
					/// <param name="id">指定ID</param>
					/// <returns>ture，成功；false，失败</returns>
					virtual bool		deleteFeature(UINT32 id);
					/// <summary>
					/// 创建一个数据表的代理对象。
					/// </summary>
					/// <returns></returns>
					virtual FD::Utility::DB::Interface::ITableProxy* createTableProxy();

				protected:
					/// <summary>
					/// 默认构造函数
					/// </summary>
					IFeatureClass();
				private:
					/// <summary>
					/// 拷贝构造函数
					/// </summary>
					C_DISABLE_COPY(IFeatureClass);
				};
			}
		}
	}
}

#endif
